package com.harisucici.websocketlib.entities.send;

import android.text.TextUtils;

import androidx.room.TypeConverter;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;

public class P2PTypeConverter {

    Gson gson = new Gson();

    @TypeConverter
    public P2PSend p2PSend(String s) {
        if (TextUtils.isEmpty(s)) {
            return new P2PSend();
        }

        Type type = new TypeToken<P2PSend>() {
        }.getType();

        return gson.fromJson(s, type);
    }

    @TypeConverter
    public String toString(P2PSend p2PSend) {
        return gson.toJson(p2PSend);
    }

}